package com.fcl.oschina.model;

import com.fcl.mylibrary.http.HttpClient;
import com.fcl.mylibrary.util.FLog;
import com.fcl.mylibrary.util.StringUtil;
import com.fcl.oschina.Constant;
import com.fcl.oschina.entity.BaseReturn;
import com.fcl.oschina.entity.ListResult;
import com.fcl.oschina.entity.NewItem;
import com.fcl.oschina.entity.UserEntity;
import com.fcl.oschina.ui.activity.UserInfoView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * Created by Administrator on 2017/3/23.
 */

public class UserInfoModel {

    private String TAG = "UserInfoModel";
    private UserInfoView mView;

    public UserInfoModel(UserInfoView view) {
        mView = view;
    }

    public void getUserInfo(int id) {
        String url = Constant.BASE_URL+"action/apiv2/user_info?id="+id;
        FLog.error(TAG, "url:"+url);
        HttpClient client = new HttpClient(url, new HttpClient.ResultListener() {
            @Override
            public void dealResult(String result) {
                FLog.error(TAG, result);
                Gson gson = new Gson();
                BaseReturn baseReturn = gson.fromJson(result, new TypeToken<BaseReturn<UserEntity>>(){}.getType());
                if (baseReturn.getCode() == 1) {
                    mView.setInfo((UserEntity) baseReturn.getResult());
                }
            }
        });
        client.get();
    }

}
